﻿using System;
using System.Linq;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ApplicationOne;

namespace UnitTestForwardList
{
    [TestClass]
    public class UnitTestForwardList
    {
        [TestMethod]
        public void TestMethodEmpty()
        {
            ForwardList<int> fli = new ForwardList<int>();

            Assert.AreEqual(true, fli.IsEmpty());
        }

        [TestMethod]
        public void TestMethodPushFrontAndPopFront()
        {
            
            ForwardList<int> fli = new ForwardList<int>();

            fli.PushFront(10);
            Assert.AreEqual(false, fli.IsEmpty());
            Assert.AreEqual(10, fli.PopFront());
            fli.PushFront(10);
            fli.PushFront(20);
            fli.PushFront(30);
            fli.PushFront(40);
            Assert.AreEqual(40, fli.PopFront());
            Assert.AreEqual(30, fli.PopFront());
            Assert.AreEqual(20, fli.PopFront());
            Assert.AreEqual(10, fli.PopFront());
            
        }

        [TestMethod]
        public void TestPropertyCount()
        {

            ForwardList<int> fli = new ForwardList<int>();
            Assert.AreEqual(0, fli.Count);
            
            fli.PushFront(10);
            Assert.AreEqual(1, fli.Count);
            fli.PushFront(20);
            Assert.AreEqual(2, fli.Count);
            fli.PushFront(30);
            Assert.AreEqual(3, fli.Count);
            fli.PushFront(40);
            Assert.AreEqual(4, fli.Count);
        }

        [TestMethod]
        public void TestMethodRemove()
        {
            Trace.WriteLine("TestMethodRemove, start");
                    
            ForwardList<int> fli = new ForwardList<int>();
            Assert.AreEqual(0, fli.Count);

            fli.PushFront(10);
            fli.PushFront(20);
            fli.PushFront(30);
            fli.PushFront(40);

            fli.Remove(40);
            Assert.AreEqual(30, fli.Front());
            fli.Remove(20);
            Assert.AreEqual(30, fli.Front());

            fli.PopFront();
            Assert.AreEqual(10, fli.Front());

            fli.Remove(20);
            Assert.AreEqual(1, fli.Count);
            fli.Remove(10);
            Assert.AreEqual(0, fli.Count);
        }

        [TestMethod]
        public void TestMethodGetEnumeration()
        {
            ForwardList<int> fli = new ForwardList<int>();
            Assert.AreEqual(0, fli.Count);

            fli.PushFront(10);
            fli.PushFront(20);
            fli.PushFront(30);
            fli.PushFront(40);

            int i = 0;
            foreach (var v  in fli)
            {
                Assert.AreEqual(40-i*10, v);
                i++;
            }
        }

        [TestMethod]
        public void TestMethodContains()
        {
            ForwardList<int> fli = new ForwardList<int>();
            

            fli.PushFront(10);
            Assert.AreEqual(true, fli.Contains(10));
            fli.PushFront(20);
            Assert.AreEqual(true, fli.Contains(20));
            fli.PushFront(30);
            fli.PushFront(40);


            Assert.AreEqual(true, fli.Contains(10));
            Assert.AreEqual(true, fli.Contains(20));
            Assert.AreEqual(true, fli.Contains(30));
            Assert.AreEqual(true, fli.Contains(40));

            Assert.AreEqual(false, fli.Contains(22));
            
        }



    }
}
